package com.wanxi.dangdang.controller.back.user;

import com.github.pagehelper.PageInfo;
import com.wanxi.dangdang.common.CommonResult;
import com.wanxi.dangdang.model.pojo.BUser;
import com.wanxi.dangdang.model.vo.BUserAddVo;
import com.wanxi.dangdang.model.vo.BUserUpdateVo;
import com.wanxi.dangdang.model.vo.BUserPageVo;
import com.wanxi.dangdang.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author: WangRui
 * @Description:
 * @Date: Created in 2021/8/30 0030
 * @Version: 1.0
 */
@Api(tags = "B端用户后端管理 （需要登录）")
// uri admin写全  数据校验 补充 ,dto service层返回对象 更新等等日志
@RestController("BackUserController")
@RequestMapping("/back/a/user")

public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/repassword")
    @ApiOperation("重置B端用户密码")
    @ApiParam(value = "重置B端用户id参数", required = true)
    private CommonResult reSetPassword(@RequestParam("id") Long id){
        userService.repassword(id);
        return CommonResult.success();
    }
    @PostMapping("/add")
    @ApiOperation("添加B端用户")
    private CommonResult add(@RequestBody BUserAddVo bUserAddVo){
        userService.add(bUserAddVo);
        return CommonResult.success();
    }
    @PostMapping("/findPage")
    @ApiOperation("分页查询B端用户")
    private CommonResult<PageInfo<BUser>> findPage(@RequestBody BUserPageVo bUserPageVo){
        PageInfo<BUser> page = userService.findPage(bUserPageVo);
        return CommonResult.success(page,"成功");
    }
    @GetMapping("/findById")
    @ApiOperation("查询B端用户通过id")
    @ApiParam(value = "查询B端用户id", required = true)
    private CommonResult<BUser> findById(@RequestParam("id") Long id){
        BUser byId = userService.findById(id);
        return CommonResult.successData(byId);
    }
    @PostMapping("/updateById")
    @ApiOperation("更新B端用户通过id")
    private CommonResult updateById(@RequestBody BUserUpdateVo bUserUpdateVo){
        userService.updateById(bUserUpdateVo);
        return CommonResult.success();
    }
    @PostMapping("/deleteById")
    @ApiOperation("删除B端用户通过Id")
    @ApiParam(value = "删除用户id参数", required = true)
    private CommonResult deleteById(@RequestParam("id") Long id){
        userService.deleteById(id);
        return CommonResult.success();
    }

}
